"""
1.学习目标
    必须掌握selenium中使用EC模块进行元素定位
2.语法
    presence_of_element_located(locator)
        - locator:定位器，元组类型(元素定位方法,方法对应的值)：
            (By.ID,"ID属性值")
            (By.NAME,"NAME属性值")
            (By.CLASS_NAME,"CLASS_NAME属性值")
            (By.PARTIAL_LINK_TEXT,"部分文本值")
            (By.XPATH,"XPATH表达式")
            (By.CSS_SELECTOR,"CSS选择器")
"""
# 1. 导入需要的包
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

# 2. 创建浏览器对象,并打开指定网页
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("http://www.baidu.com")

# 3. 元素定位+元素操作
locator = (By.ID, "kw")
search = EC.presence_of_element_located(locator)(driver)
search.send_keys("EC模块")

# 3.1 显式等待+EC模块
# 判断元素是否可见
search_box = WebDriverWait(driver, 10).until(EC.presence_of_element_located(locator))
search_box.send_keys("显示等待+EC模块")

# 定位百度首页的input标签
input_loc = (By.TAG_NAME, "input")
input_tag = WebDriverWait(driver, 10).until(EC.presence_of_element_located(input_loc))
print(input_tag)

# 4.关闭浏览器
sleep(3)
driver.quit()